package com.lineage.data.item_etcitem.shop;

import com.lineage.data.executor.ItemExecutor;
import com.lineage.server.model.Instance.L1ItemInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.serverpackets.S_Message_YN;
import com.lineage.server.serverpackets.S_ServerMessage;
import com.lineage.server.serverpackets.ServerBasePacket;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class UserName extends ItemExecutor {
  private static final Log _log = LogFactory.getLog(UserName.class);
  
  public static ItemExecutor get() {
    return new UserName();
  }
  
  public void execute(int[] data, L1PcInstance pc, L1ItemInstance item) {
    if (item == null)
      return; 
    if (pc == null)
      return; 
    if (pc.isGhost())
      return; 
    if (pc.isDead())
      return; 
    if (pc.isTeleport())
      return; 
    if (pc.getLawful() < 32767) {
      pc.sendPackets((ServerBasePacket)new S_ServerMessage("\\fT正义值必须为32767才可以使用"));
      return;
    } 
    if (pc.isPrivateShop()) {
      pc.sendPackets((ServerBasePacket)new S_ServerMessage("\\fT请先结束商店村模式!"));
      return;
    } 
    Object[] petList = pc.getPetList().values().toArray();
    if (petList.length > 0) {
      pc.sendPackets((ServerBasePacket)new S_ServerMessage("\\fT请先回收宠物!"));
      return;
    } 
    if (pc.getHierarchs() != null) {
      pc.sendPackets((ServerBasePacket)new S_ServerMessage("\\fT请先回收祭司!"));
      return;
    } 
    if (!pc.getDolls().isEmpty()) {
      pc.sendPackets((ServerBasePacket)new S_ServerMessage("\\fT请先回收魔法娃娃!"));
      return;
    } 
    if (pc.getParty() != null) {
      pc.sendPackets((ServerBasePacket)new S_ServerMessage("\\fT请先退出队伍!"));
      return;
    } 
    if (pc.getClanid() != 0) {
      pc.sendPackets((ServerBasePacket)new S_ServerMessage("\\fT请先退出血盟!"));
      return;
    } 
    try {
      pc.sendPackets((ServerBasePacket)new S_Message_YN(325));
      pc.rename(true);
    } catch (Exception e) {
      _log.error(e.getLocalizedMessage(), e);
    } 
  }
}
